# -*- coding: utf-8 -*-
# @Time    : 2020/9/27 17:55
# @Author  : Mr. Cui
# @File    : views.py
# @Software: PyCharm
from flask import request, make_response

from . import d_bot
from ...apps.d_bot.service.gen_qr import *
from ...libs import const
from ...libs.framework import *
from ...libs.validate_params import validate_params


@d_bot.route('/receive_dmsg', methods=['POST'])
@validate_params(params=["senderNick", "sessionWebhook"])
def receive_dmsg():
    data = request.get_json()
    name = data["senderNick"]
    sessionWebhook = data["sessionWebhook"]
    content = data["text"]["content"]
    if main(sessionWebhook, name, content):
        return make_response("", const.SUCCESS_204)
    return make_response(result_msg(const.FAIL_400, "系统异常，请联系管理员"), const.FAIL_400)


@d_bot.route('/test')
def test():
    ding_token = "https://oapi.dingtalk.com/robot/sendBySession?session=0465ccb69bd1f23c934842d38b07d458"
    name = "崔金月"
    text = "161"
    if main(ding_token, name, text):
        return make_response("", const.SUCCESS_204)
    return make_response(result_msg(const.FAIL_400, "系统异常，请联系管理员"), const.FAIL_400)
